import java.util.Arrays;

public class 二分法排序 {
    
    public static void main(String[] args) {
        
        int[] arr = new int[]{5,2,3,1,5,3,6,7,12,6};

        System.out.println(Arrays.toString(arr));

        //排序
        doSort(arr);

        System.out.println(Arrays.toString(arr));

    }

    private static void doSort(int[] arr){

        for(int i=0; i<arr.length; i++){

            int temp = arr[i];
            int left = 0;
            int right = arr.length - 1;
            int middle = -1;

            while (right >= left) {

                middle = (left+right) / 2;

                if(arr[middle] > temp){

                    right = middle -1;

                } else {

                    left = middle + 1;
                }

            }

            arr[i] = arr[middle];
            arr[middle] = temp;

            
        }
    }
}
